from django.test import TestCase
from magictags.models import Tag
from magictags.testdata.models import TestItem
from magictags.templatetags import magictags


class TagTest(TestCase):
    def setUp(self):
        #create some tags
        self.tag1 = Tag.objects.create(name="Adobe Air", slug="adobe-air")
        self.tag1.save()
        self.tag2 = Tag.objects.create(name="Adobe Flex", slug="adobe-flex")
        self.tag2.save()
        self.tag3 = Tag.objects.create(name="Javascript", slug="javascript")
        self.tag3.save()
        
        #create list of objects that have tags applied to them
        self.item1 = TestItem(name="item 1")
        self.item1.save()
        self.item1.tags.add(self.tag1)
        self.item1.tags.add(self.tag2)
        
        self.item2 = TestItem(name="item 2", tags = [self.tag2])
        self.item2.save()
        self.item2.tags.add(self.tag2)
        
        self.item3 = TestItem(name="item 3", tags = [self.tag1])
        self.item3.save()
        self.item3.tags.add(self.tag1)
        
        self.testobjects = TestItem.objects.all()
        
    def testCreation(self):
        self.assertEquals(self.tag1.name, "Adobe Air")
        self.assertEquals(self.tag1.slug, "adobe-air")
        
        #test tag assignment
        self.assertEquals(self.item1.name, "item 1")
        self.assertEquals(self.item1.tags, [self.tag1, self.tag2])
        
        item1 = TestItem.objects.get(name="item 1")
        self.assertEqual(item1.name, self.item1.name)
        
        #test object list
        self.assertEquals(count(self.testobjects), 3)
        
    #test the template tag
    def testGetMagictags(self):
        #pass in a list of objects
        response = magictags.get_magictags(None, "token")
        self.assertEquals(response, 4)
        
class SimpleTest(TestCase):
    def test_basic_addition(self):
        """
        Tests that 1 + 1 always equals 2.
        """
        self.failUnlessEqual(1 + 1, 2)



